//var btn=document.getElementById("btn2");
/*var handler=function(){
	alert("hello");
};*/
/*document.body.onclick=function(event){
	//alert(event.currentTarget===document.body);
	//alert(this===document.body);
	//alert(event.target===btn);
	//alert(event.target.id);
}*/
/*var EventUtil={
	addHandler:function(element,type,handler){
		if(element.addEventListener){
			element.addEventListener(type,handler,false);
		}else if(element.attachEvent){
			element.attachEvent("on"+type,handler);
		}else{
			var event="on"+type;
			element.event=handler;
		}
	},
	removeHandler:function(element,type,handler){
		if(element.removeEventListener){
			element.removeEventListener(type,handler,false);
		}else if(element.detachEvent){
			element.detachEvent("on"+type,handler);
		}else{
			var event="on"+type;
			element.event=null;
		}
	}
};
EventUtil.addHandler(btn,"click",handler);*/
/*var handler=function(event){
	switch(event.type){
		case "click":
			alert("clicked");break;
		case "mouseover":
			event.target.style.backgroundColor="red";break;
		case "mouseout":
			event.target.style.backgroundColor="";break;
	}
};
btn.onclick=handler;
btn.onmouseover=handler;
btn.onmouseout=handler;*/
/*btn.onclick=function(event){
	alert("clicked");
	event.stopPropagation();
}
document.body.onclick=function(event){
	alert("body clicked");
}*/
/*btn.onclick=function(event){
	alert(event.eventPhase);
};
btn.addEventListener("click",function(event){
	alert(event.eventPhase);
},true);
document.body.onclick=function(event){
	alert(event.eventPhase);
}*/
/*btn.onclick=function(){
	var event=window.event;
	alert(event.type);
};*/
/*btn.onclick=function(){
	alert(window.event.srcElement===this);
};
btn.attachEvent("onclick",function(event){
	alert(event.srcElement===this);
});*/
/*EventUtil.addHandler(window,"load",function(event){
	alert("ccc");
});*/
/*var list=document.getElementById("mylist");
EventUtil.addHandler(list,"click",function(event){
	event=EventUtil.getEvent(event);
	//alert("Client coordinates: "+event.screenX+","+event.screenY);
	var keys=new Array();
	
	if(event.shiftKey){
		keys.push("shift");
	}
	if(event.ctrlKey){
		keys.push("ctrl");
	}
	if(event.metaKey){
		keys.push("meta");
	}
	if(event.altKey){
		keys.push("alt");
	}
	
	alert("Keys: "+keys.join(","));
});*/
/*var list=document.getElementById("mylist");
EventUtil.addHandler(list,"mouseout",function(event){
	event=EventUtil.getEvent(event);
	var target=EventUtil.getTarget(event);
	var relatedTarget=EventUtil.getRelatedTarget(event);
	alert("Mouse out of "+target.tagName+"to"+relatedTarget.tagName);
});*/
/*var list=document.getElementById("mylist");
EventUtil.addHandler(list,"mousedown",function(event){
	event=EventUtil.getEvent(event);
	alert(EventUtil.getButton(event));
});*/
/*var textbox=document.getElementById("myText");
EventUtil.addHandler(textbox,"keypress",function(event){
	event=EventUtil.getEvent(event);
	alert(EventUtil.getCharCode(event));
});*/
/*EventUtil.addHandler(window,"load",function(event){
	var list=document.getElementById("mylist");
	EventUtil.addHandler(document,"DOMSubtreeModified",function(event){
		alert(event.type);
		alert(event.target);
	});
	EventUtil.addHandler(document,"DOMNodeRemoved",function(event){
		alert(event.type);
		alert(event.target);
		alert(event.relatedNode);
	});
	EventUtil.addHandler(list.firstChild,"DOMNodeRemovedFromDocument",function(event){
		alert(event.type);
		alert(event.target);
	});
	list.parentNode.removeChild(list);
});*/
/*EventUtil.addHandler(window,"load",function(event){
	var list=document.getElementById("mylist");
	var item=document.createElement("li");
	item.appendChild(document.createTextNode("Item 4"));
	
	EventUtil.addHandler(document,"DOMSubtreeModified",function(event){
		alert("1");
	});
	EventUtil.addHandler(document,"DOMNodeInserted",function(event){
		alert("2");
	});
	EventUtil.addHandler(item,"DOMNodeInsertedIntoDocument",function(event){
		alert("3");
	});
	list.appendChild(item);
});*/
var EventUtil={
	addHandler:function(element,type,handler){
		if(element.addEventListener){
			element.addEventListener(type,handler,false);
		}else if(element.attachEvent){
			element.attachEvent("on"+type,handler);
		}else{
			var event="on"+type;
			element.event=handler;
		}
	},
	removeHandler:function(element,type,handler){
		if(element.removeEventListener){
			element.removeEventListener(type,handler,false);
		}else if(element.detachEvent){
			element.detachEvent("on"+type,handler);
		}else{
			var event="on"+type;
			element.event=null;
		}
	},
	getEvent:function(event){
		return event? event:window.event;
	},
	getTarget:function(event){
		return event.target||event.srcElement;
	},
	preventDefault:function(event){
		if(event.preventDefault){
			event.preventDefault();
		}else{
			event.returnValue=false;
		}
	},
	stopPropagation:function(event){
		if(event.stopPropagation){
			event.stopPropagation();
		}else{
			event.cancelBubble=false;
		}
	},
	getRelatedTarget:function(event){
		if(event.relatedTarget){
			return event.relatedTarget;
		}else if(event.toElement){
			return event.toElement;
		}else if(event.fromElement){
			return event.fromElement;
		}else{
			return null;
		}
	},
	getButton:function(event){
		if(document.implementation.hasFeature("MouseEvents","2.1")){
			return event.button;
		}else{
			switch(event.button){
				case 0:case 1:case 3:case 5:case 7:return 0;
				case 2:case 6:return 2;
				case 4:return 1;
			}
		}
	},
	getCharCode:function(event){
		if(typeof event.charCode==="number"){
			return event.charCode;
		}else{
			return event.keyCode;
		}
	}
};
//上下文菜单
EventUtil.addHandler(window,"load",function(event){
	var div=document.getElementById("myDiv");

	EventUtil.addHandler(div,"contextmenu",function(event){
		event=EventUtil.getEvent(event);
		EventUtil.preventDefault(event);
		
		var menu=document.getElementById("myMenu");
		menu.style.left=event.clientX+"px";
		menu.style.top=event.clientY+"px";
		menu.style.visibility="visible";
	});
	EventUtil.addHandler(document,"click",function(event){
		document.getElementById("myMenu").style.visibility="hidden";
	});
});


var form=document.getElementById("myForm");
var colorFields=form.elements["color"];
alert(colorFields[0]===form.elements[0]);
/*EventUtil.addHandler(window,"load",function(event){
	alert("ccc");
});*/

